<?php
class logs
{
	var $ipsclass;
	var $LIMIT = 25;
	
	function auto_run()
	{
		if($this->ipsclass->input['CODE'] == 'fee')
		{
			$this->fee_logs();
		}
		elseif($this->ipsclass->input['CODE'] == 'reward')
		{
			$this->reward_logs();
		}
		else
		{
			$this->ipsclass->Error(array('MSG'=>'market_noview'));
		}
	}
	
	function fee_logs()
	{
		$this->ipsclass->input['st'] = intval($this->ipsclass->input['st']);
		
		$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'market_fee_logs','where'=>"member_id=".$this->ipsclass->member['id']));
		$page_links = $this->ipsclass->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																'PER_PAGE'     => $this->LIMIT,
																'CUR_ST_VAL'   => $this->ipsclass->input['st'],
																'L_SINGLE'     => $this->ipsclass->compiled_templates['skin_global']->pagination_compile($this->ipsclass->compiled_templates['skin_global']->pagination_make_jump(),"","",$this->ipsclass->compiled_templates['skin_global']->pagination_current_page(1),"","",1,$this->LIMIT,$this->ipsclass->market_class->base_url."CODE=fee",0,'st'),
																'BASE_URL'     => $this->ipsclass->market_class->base_url."CODE=fee",
																'USE_ST'       => 'st'
														)	);
		
		$logs = "";
		$this->ipsclass->DB->build_query(array('select'=>'*','from'=>'market_fee_logs','where'=>"member_id=".$this->ipsclass->member['id'],'order'=>'l_time DESC','limit'=>array($this->ipsclass->input['st'],$this->LIMIT)));
		$this->ipsclass->DB->exec_query();
		while($log = $this->ipsclass->DB->fetch_row())
		{
			$log['l_time'] = $this->ipsclass->get_date($log['l_time'],'LONG');
			$log['l_amount'] = $this->ipsclass->numbers->format_currency($log['l_amount']);
			if($log['location'] == 'buy')
			{
				$log['location'] = $this->ipsclass->lang['tax_on_items'];
			}
			elseif(strstr($log['location'],'plugin:') === $log['location'])
			{
				$info = explode(":",$log['location']);
				if(is_array($this->ipsclass->cache['market_plugin'][$info[1]]))
				{
					$log['location'] = sprintf($this->ipsclass->lang['from_x_plugin'],$this->ipsclass->cache['market_plugin'][$info[1]]['name']);
				}
				else
				{
					$log['location'] = sprintf($this->ipsclass->lang['from_x_plugin'],$info[2]);
				}
			}
			elseif(strstr($log['location'],'item:') === $log['location'])
			{
				$info = explode(":",$log['location']);
				if(is_array($this->ipsclass->cache['market_items'][$info[1]]))
				{
					$log['location'] = sprintf($this->ipsclass->lang['from_x_item'],$this->ipsclass->cache['market_items'][$info[1]]['item_name']);
				}
				else
				{
					$log['location'] = sprintf($this->ipsclass->lang['from_x_item'],$info[2]);
				}
			}
			else
			{
				continue;
			}
			
			$logs[] = $log;
		}
		
		$this->ipsclass->nav[] = "<a href='".$this->ipsclass->market_class->base_url."CODE=fee'>".$this->ipsclass->lang['log_fee']."</a>";
		
		$this->ipsclass->output = $this->ipsclass->compiled_templates['skin_market']->log_page('log_fee',$logs,$page_links);
	}
	
	function reward_logs()
	{
		$this->ipsclass->input['st'] = intval($this->ipsclass->input['st']);
		
		$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'market_reward_logs','where'=>"member_id=".$this->ipsclass->member['id']));
		$page_links = $this->ipsclass->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																'PER_PAGE'     => $this->LIMIT,
																'CUR_ST_VAL'   => $this->ipsclass->input['st'],
																'L_SINGLE'     => $this->ipsclass->compiled_templates['skin_global']->pagination_compile($this->ipsclass->compiled_templates['skin_global']->pagination_make_jump(),"","",$this->ipsclass->compiled_templates['skin_global']->pagination_current_page(1),"","",1,$this->LIMIT,$this->ipsclass->market_class->base_url."CODE=reward",0,'st'),
																'BASE_URL'     => $this->ipsclass->market_class->base_url."CODE=reward",
																'USE_ST'       => 'st'
														)	);
		
		$logs = "";
		$this->ipsclass->DB->build_query(array('select'=>'*','from'=>'market_reward_logs','where'=>"member_id=".$this->ipsclass->member['id'],'order'=>'l_time DESC','limit'=>array($this->ipsclass->input['st'],$this->LIMIT)));
		$this->ipsclass->DB->exec_query();
		while($log = $this->ipsclass->DB->fetch_row())
		{
			$log['l_time'] = $this->ipsclass->get_date($log['l_time'],'LONG');
			$log['l_amount'] = $this->ipsclass->numbers->format_currency($log['l_amount']);
			if($log['location'] == 'registered')
			{
				$log['location'] = $this->ipsclass->lang['reward_on_register'];
			}
			elseif($log['location'] == 'posts')
			{
				$log['location'] = $this->ipsclass->lang['reward_on_post'];
			}
			elseif(strstr($log['location'],'plugin:') === $log['location'])
			{
				$info = explode(":",$log['location']);
				if(is_array($this->ipsclass->cache['market_plugin'][$info[1]]))
				{
					$log['location'] = sprintf($this->ipsclass->lang['from_x_plugin'],$this->ipsclass->cache['market_plugin'][$info[1]]['name']);
				}
				else
				{
					$log['location'] = sprintf($this->ipsclass->lang['from_x_plugin'],$info[2]);
				}
			}
			elseif(strstr($log['location'],'item:') === $log['location'])
			{
				$info = explode(":",$log['location']);
				if(is_array($this->ipsclass->cache['market_items'][$info[1]]))
				{
					$log['location'] = sprintf($this->ipsclass->lang['from_x_item'],$this->ipsclass->cache['market_items'][$info[1]]['item_name']);
				}
				else
				{
					$log['location'] = sprintf($this->ipsclass->lang['from_x_item'],$info[2]);
				}
			}
			else
			{
				continue;
			}
			
			$logs[] = $log;
		}
		
		$this->ipsclass->nav[] = "<a href='".$this->ipsclass->market_class->base_url."CODE=reward'>".$this->ipsclass->lang['log_reward']."</a>";
		
		$this->ipsclass->output = $this->ipsclass->compiled_templates['skin_market']->log_page('log_fee',$logs,$page_links);
	}
}
?>